package com.ecommerce.product.entity;

import com.baomidou.mybatisplus.annotation.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import javax.persistence.*;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 商品实体类
 * 
 * @author ecommerce-team
 * @version 1.0.0
 */
@Entity
@Table(name = "product")
@TableName("product")
public class Product {
    
    /**
     * 商品ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    
    /**
     * 商品标题
     */
    @NotBlank(message = "商品标题不能为空")
    @Column(name = "title", nullable = false, length = 200)
    private String title;
    
    /**
     * 商品副标题
     */
    @Column(name = "subtitle", length = 500)
    private String subtitle;
    
    /**
     * 商品价格
     */
    @NotNull(message = "商品价格不能为空")
    @DecimalMin(value = "0.01", message = "商品价格必须大于0")
    @Column(name = "price", nullable = false, precision = 10, scale = 2)
    private BigDecimal price;
    
    /**
     * 商品原价
     */
    @Column(name = "original_price", precision = 10, scale = 2)
    private BigDecimal originalPrice;
    
    /**
     * 折扣
     */
    @Column(name = "discount", precision = 3, scale = 1)
    private BigDecimal discount;
    
    /**
     * 库存数量
     */
    @NotNull(message = "库存数量不能为空")
    @Column(name = "stock", nullable = false)
    private Integer stock;
    
    /**
     * 销量
     */
    @Column(name = "sales", columnDefinition = "int default 0")
    private Integer sales;
    
    /**
     * 商品分类ID
     */
    @Column(name = "category_id")
    private Long categoryId;
    
    /**
     * 商品品牌ID
     */
    @Column(name = "brand_id")
    private Long brandId;
    
    /**
     * 商品状态：0-下架，1-上架
     */
    @Column(name = "status", columnDefinition = "tinyint default 1")
    private Integer status;
    
    /**
     * 商品主图列表（JSON格式）
     */
    @Column(name = "images", columnDefinition = "text")
    private String images;
    
    /**
     * 商品详情图列表（JSON格式）
     */
    @Column(name = "detail_images", columnDefinition = "text")
    private String detailImages;
    
    /**
     * 商品描述
     */
    @Column(name = "description", columnDefinition = "text")
    private String description;
    
    /**
     * 好评率
     */
    @Column(name = "review_rate", precision = 5, scale = 2, columnDefinition = "decimal(5,2) default 100.00")
    private BigDecimal reviewRate;
    
    /**
     * 评价数量
     */
    @Column(name = "review_count", columnDefinition = "int default 0")
    private Integer reviewCount;
    
    /**
     * 商品重量（克）
     */
    @Column(name = "weight")
    private Integer weight;
    
    /**
     * 商品尺寸
     */
    @Column(name = "dimensions", length = 100)
    private String dimensions;
    
    /**
     * 是否推荐：0-否，1-是
     */
    @Column(name = "is_recommend", columnDefinition = "tinyint default 0")
    private Integer isRecommend;
    
    /**
     * 是否热销：0-否，1-是
     */
    @Column(name = "is_hot", columnDefinition = "tinyint default 0")
    private Integer isHot;
    
    /**
     * 是否新品：0-否，1-是
     */
    @Column(name = "is_new", columnDefinition = "tinyint default 0")
    private Integer isNew;
    
    /**
     * 排序权重
     */
    @Column(name = "sort_order", columnDefinition = "int default 0")
    private Integer sortOrder;
    
    /**
     * 创建时间
     */
    @TableField(fill = FieldFill.INSERT)
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;
    
    /**
     * 更新时间
     */
    @TableField(fill = FieldFill.INSERT_UPDATE)
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;
    
    /**
     * 逻辑删除：0-未删除，1-已删除
     */
    @TableLogic
    @Column(name = "deleted", columnDefinition = "tinyint default 0")
    private Integer deleted;
    
    // 以下字段不存储到数据库，仅用于返回给前端
    
    /**
     * 商品规格列表（不存储到数据库）
     */
    @Transient
    @TableField(exist = false)
    private List<ProductSpec> specs;
    
    /**
     * 商品促销信息列表（不存储到数据库）
     */
    @Transient
    @TableField(exist = false)
    private List<ProductPromotion> promotions;
    
    /**
     * 商品评价列表（不存储到数据库）
     */
    @Transient
    @TableField(exist = false)
    private List<ProductReview> reviews;
    
    /**
     * 商品主图列表（不存储到数据库）
     */
    @Transient
    @TableField(exist = false)
    private List<String> imageList;
    
    /**
     * 商品详情图列表（不存储到数据库）
     */
    @Transient
    @TableField(exist = false)
    private List<String> detailImageList;
    
    // Getter and Setter methods
    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }
    
    public String getTitle() { return title; }
    public void setTitle(String title) { this.title = title; }
    
    public String getSubtitle() { return subtitle; }
    public void setSubtitle(String subtitle) { this.subtitle = subtitle; }
    
    public BigDecimal getPrice() { return price; }
    public void setPrice(BigDecimal price) { this.price = price; }
    
    public BigDecimal getOriginalPrice() { return originalPrice; }
    public void setOriginalPrice(BigDecimal originalPrice) { this.originalPrice = originalPrice; }
    
    public BigDecimal getDiscount() { return discount; }
    public void setDiscount(BigDecimal discount) { this.discount = discount; }
    
    public Integer getStock() { return stock; }
    public void setStock(Integer stock) { this.stock = stock; }
    
    public Integer getSales() { return sales; }
    public void setSales(Integer sales) { this.sales = sales; }
    
    public Long getCategoryId() { return categoryId; }
    public void setCategoryId(Long categoryId) { this.categoryId = categoryId; }
    
    public Long getBrandId() { return brandId; }
    public void setBrandId(Long brandId) { this.brandId = brandId; }
    
    public Integer getStatus() { return status; }
    public void setStatus(Integer status) { this.status = status; }
    
    public String getImages() { return images; }
    public void setImages(String images) { this.images = images; }
    
    public String getDetailImages() { return detailImages; }
    public void setDetailImages(String detailImages) { this.detailImages = detailImages; }
    
    public String getDescription() { return description; }
    public void setDescription(String description) { this.description = description; }
    
    public BigDecimal getReviewRate() { return reviewRate; }
    public void setReviewRate(BigDecimal reviewRate) { this.reviewRate = reviewRate; }
    
    public Integer getReviewCount() { return reviewCount; }
    public void setReviewCount(Integer reviewCount) { this.reviewCount = reviewCount; }
    
    public Integer getWeight() { return weight; }
    public void setWeight(Integer weight) { this.weight = weight; }
    
    public String getDimensions() { return dimensions; }
    public void setDimensions(String dimensions) { this.dimensions = dimensions; }
    
    public Integer getIsRecommend() { return isRecommend; }
    public void setIsRecommend(Integer isRecommend) { this.isRecommend = isRecommend; }
    
    public Integer getIsHot() { return isHot; }
    public void setIsHot(Integer isHot) { this.isHot = isHot; }
    
    public Integer getIsNew() { return isNew; }
    public void setIsNew(Integer isNew) { this.isNew = isNew; }
    
    public Integer getSortOrder() { return sortOrder; }
    public void setSortOrder(Integer sortOrder) { this.sortOrder = sortOrder; }
    
    public LocalDateTime getCreateTime() { return createTime; }
    public void setCreateTime(LocalDateTime createTime) { this.createTime = createTime; }
    
    public LocalDateTime getUpdateTime() { return updateTime; }
    public void setUpdateTime(LocalDateTime updateTime) { this.updateTime = updateTime; }
    
    public Integer getDeleted() { return deleted; }
    public void setDeleted(Integer deleted) { this.deleted = deleted; }
    
    public List<ProductSpec> getSpecs() { return specs; }
    public void setSpecs(List<ProductSpec> specs) { this.specs = specs; }
    
    public List<ProductPromotion> getPromotions() { return promotions; }
    public void setPromotions(List<ProductPromotion> promotions) { this.promotions = promotions; }
    
    public List<ProductReview> getReviews() { return reviews; }
    public void setReviews(List<ProductReview> reviews) { this.reviews = reviews; }
    
    public List<String> getImageList() { return imageList; }
    public void setImageList(List<String> imageList) { this.imageList = imageList; }
    
    public List<String> getDetailImageList() { return detailImageList; }
    public void setDetailImageList(List<String> detailImageList) { this.detailImageList = detailImageList; }
}